package com.xdf.ecommerce.sampler;

import brave.sampler.RateLimitingSampler;
import brave.sampler.Sampler;
import org.springframework.cloud.sleuth.sampler.ProbabilityBasedSampler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 编码的方式设置 sleuth 采样策略，使用本方法则不需在 yml 中配置端点 sleuth.sampler
 * @author chanchaw
 * @create 2025-10-24 16:18
 */
// @Configuration
public class SamplerConfig {
    /**
     * RateLimitingSampler采样策略 - 限速采样
     * 每秒采样100个请求
     * @return
     */
    @Bean
    public Sampler sampler(){
        return RateLimitingSampler.create(100);
    }
//    @Bean
//    public Sampler defaultSampler(){
//        return ProbabilityBasedSampler.create(0.5f);
//    }
}
